﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using MaxStudio.Concrete.DBUtility;
using MaxStudio.Concrete.Server.Dao;
using MaxStudio.Concrete.Server.Interface;

namespace MaxStudio.Concrete.Server.Service
{
    public class RPTSiteOpeningRecordsService : ServiceHandle, ISiteOpeningRecords
    {
        #region ISiteOpeningRecords Members

        public OperationResult<List<tb_RPT_SiteOpeningRecord>> GetAllSiteOpeningRecords()
        {
            OperationResult<List<tb_RPT_SiteOpeningRecord>> result = new OperationResult<List<tb_RPT_SiteOpeningRecord>>();
            List<tb_RPT_SiteOpeningRecord> list = new List<tb_RPT_SiteOpeningRecord>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetAllSiteOpeningRecords();
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<List<tb_RPT_SiteOpeningRecord>> GetSiteOpeningRecordsByInputDate(DateTime inputdate)
        {
            OperationResult<List<tb_RPT_SiteOpeningRecord>> result = new OperationResult<List<tb_RPT_SiteOpeningRecord>>();
            List<tb_RPT_SiteOpeningRecord> list = new List<tb_RPT_SiteOpeningRecord>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetSiteOpeningRecordsByInputDate(inputdate);
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<List<tb_RPT_SiteOpeningRecord>> GetSiteOpeningRecordsByInputDate(DateTime inputdate1, DateTime inputdate2)
        {
            OperationResult<List<tb_RPT_SiteOpeningRecord>> result = new OperationResult<List<tb_RPT_SiteOpeningRecord>>();
            List<tb_RPT_SiteOpeningRecord> list = new List<tb_RPT_SiteOpeningRecord>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetSiteOpeningRecordsByInputDate(inputdate1, inputdate2);
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<List<tb_RPT_SiteOpeningRecord>>  GetSiteOpeningRecordsByContition(string strWeather, string strInputDate, string strProjectName
                                                                   , string strProjectUnit, string strConstructionSite
                                                                   , string strStrengthGrade, string strDesignSlump
                                                                   , string strFactorySlump, string strCement, string strOpeningTime
                                                                   , string strReserveVolume, string strUsingCement, string strProductionLine
                                                                   , string strApproachTo, string strCarryOn, string strCreateBy) 
        {
            OperationResult<List<tb_RPT_SiteOpeningRecord>> result = new OperationResult<List<tb_RPT_SiteOpeningRecord>>();
            List<tb_RPT_SiteOpeningRecord> list = new List<tb_RPT_SiteOpeningRecord>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetSiteOpeningRecordsByContition( strWeather,  strInputDate,  strProjectName
                                                                   ,  strProjectUnit,  strConstructionSite
                                                                   ,  strStrengthGrade,  strDesignSlump
                                                                   ,  strFactorySlump,  strCement,  strOpeningTime
                                                                   ,  strReserveVolume,  strUsingCement,  strProductionLine
                                                                   ,  strApproachTo,  strCarryOn,  strCreateBy);
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_RPT_SiteOpeningRecord> GetSiteOpeningRecordsById(int id)
        {
            ConcreteDaoDataContext dataContext = getDateContext();
            OperationResult<tb_RPT_SiteOpeningRecord> result = new OperationResult<tb_RPT_SiteOpeningRecord>();
            tb_RPT_SiteOpeningRecord siteOpeningRecord;
            try
            {
                siteOpeningRecord = dataContext.GetSiteOpeningRecordsById(id);
                if (siteOpeningRecord == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = siteOpeningRecord;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_RPT_SiteOpeningRecord> CreateSiteOpeningRecords(tb_RPT_SiteOpeningRecord entity)
        {
            OperationResult<tb_RPT_SiteOpeningRecord> result = new OperationResult<tb_RPT_SiteOpeningRecord>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.CreateSiteOpeningRecords(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_RPT_SiteOpeningRecord> ModifySiteOpeningRecords(tb_RPT_SiteOpeningRecord entity)
        {
            OperationResult<tb_RPT_SiteOpeningRecord> result = new OperationResult<tb_RPT_SiteOpeningRecord>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.ModifySiteOpeningRecords(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_RPT_SiteOpeningRecord> DeleteSiteOpeningRecords(tb_RPT_SiteOpeningRecord entity)
        {
            OperationResult<tb_RPT_SiteOpeningRecord> result = new OperationResult<tb_RPT_SiteOpeningRecord>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.DeleteSiteOpeningRecords(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        #endregion
    }
}
